package com.circle.interests.biz.api;

import com.circle.interests.biz.entity.PrizeHonglianProduct;
import com.circle.interests.biz.enums.SceneTypeEnum;
import com.circle.interests.biz.service.IPrizeGameInventoryService;
import com.circle.interests.biz.service.IPrizeGameWinRecordService;
import com.circle.interests.biz.service.IPrizeHonglianProductService;
import com.circle.prize.library.api.dto.PrizeHonglianProductDto;
import com.circle.prize.library.api.dto.game.PrizeGameInventoryDto;
import com.circle.prize.library.api.dto.game.PrizeGameWinResultDto;
import com.circle.prize.library.api.dto.game.PrizeGameWriteOffResultDto;
import com.circle.prize.library.api.service.DubboActGamePrizeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhou
 * @date 2021/12/17
 */
@Slf4j
@DubboService
public class DubboActGamePrizeServiceImpl implements DubboActGamePrizeService {

    @Resource
    private IPrizeGameInventoryService prizeGameInventoryService;
    @Resource
    private IPrizeGameWinRecordService gameWinRecordService;
    @Resource
    private IPrizeHonglianProductService prizeHonglianProductService;

    @Override
    public Boolean allocateActGameInventory(String actCode, List<PrizeGameInventoryDto> prizeInventoryList) {
        return prizeGameInventoryService.saveGameInventory(SceneTypeEnum.ACT.getCode(), actCode, prizeInventoryList);
    }

    @Override
    public PrizeGameWinResultDto winPrize(String actCode, String openId, String prizeCode, String code, Integer amount) {
        return gameWinRecordService.winPrize(SceneTypeEnum.ACT.getCode(), actCode, openId, prizeCode, code, amount);
    }

    @Override
    public PrizeGameWriteOffResultDto winAndWriteOffPrize(String actCode, String openId, String phoneNumber, String prizeCode, String uuid, Integer amount, String remark) {
        return winAndWriteOffPrize(actCode, openId, null, null, null, phoneNumber, prizeCode, uuid, amount, remark);
    }

    @Override
    public PrizeGameWriteOffResultDto winAndWriteOffPrize(String actCode, String openId, String nickname, String phoneNumber, String prizeCode, String uuid, Integer amount, String remark) {
        return winAndWriteOffPrize(actCode, openId, nickname, null, null, phoneNumber, prizeCode, uuid, amount, remark);
    }

    @Override
    public PrizeGameWriteOffResultDto winAndWriteOffPrize(String actCode, String openId, String nickname, String payAppId, String payOpenId, String phoneNumber, String prizeCode, String uuid, Integer amount, String remark) {
        return gameWinRecordService.winAndWriteOffPrize(SceneTypeEnum.ACT.getCode(), actCode, openId, nickname, payAppId, payOpenId, phoneNumber, prizeCode, uuid, amount, remark);
    }

    @Override
    public PrizeGameWriteOffResultDto writeOff(String actCode, String openId, String phoneNumber, String uuid, String remark) {
        return gameWinRecordService.writeOff(SceneTypeEnum.ACT.getCode(), actCode, openId, phoneNumber, uuid, remark);
    }

    @Override
    public PrizeHonglianProductDto getHonglianByProductCode(String productCode) {
        PrizeHonglianProduct product = prizeHonglianProductService.getByProductCode(productCode);
        PrizeHonglianProductDto dto = new PrizeHonglianProductDto();
        BeanUtils.copyProperties(product, dto);
        return dto;
    }

}
